﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace ApplicationBll
{
    public class AccessSQL
    {

        private string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=True;Data Source=D:\My Documents\Visual Studio 2008\Projects\wallet\wallet\wallet\App_Data\Database.accdb";

        public DataTable GetDataTable(string sql)
        {
            using (OleDbConnection conn = new OleDbConnection(connectionString))
            {
                conn.Open();
                OleDbCommand command = new OleDbCommand(sql, conn);
                OleDbDataAdapter ada = new OleDbDataAdapter(command);
                DataTable table = new DataTable();
                ada.Fill(table);
                return table;
            }
        }

        public object ExecuteScalar(string sql)
        {
            using (OleDbConnection conn = new OleDbConnection(connectionString))
            {
                conn.Open();
                OleDbCommand command = new OleDbCommand(sql, conn);
                return command.ExecuteScalar();
            }
        }
        public int ExecuteNonQuery(string sql,params OleDbParameter[] parames)
        {
            using (OleDbConnection conn = new OleDbConnection(connectionString))
            {
                conn.Open();
                OleDbCommand command = new OleDbCommand(sql, conn);
                command.Parameters.AddRange(parames);
                return command.ExecuteNonQuery();
            }
        }


    }
}
